/**
 * 从地址栏传值的代码
 * @param param
 * @returns
 */
function getParameter(param){
	var query = window.location.search;
	var iLen = param.length;
	var iStart = query.indexOf(param);
	if (iStart == -1)
		return "";
	iStart += iLen + 1;
	var iEnd = query.indexOf("&", iStart);
	if (iEnd == -1)
		return query.substring(iStart);
	return query.substring(iStart, iEnd);
}
layui.use('laydate', function(){
	  var laydate = layui.laydate;
	  lay('.test-item').each(function(){
		    laydate.render({
		      elem: this
		      ,trigger: 'click'
		    });
		  });
	  
	  
	 
});
layui.use('table', function(){
	var sd=getParameter("id");
	  console.log(sd)
  var table = layui.table;
	  
	//监听单元格编辑
	  table.on('edit(idTest)', function(obj){
	    var value = obj.value //得到修改后的值
	    ,data = obj.data //得到所在行所有键值
	    ,field = obj.field; //得到字段
	    layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
	  });
	  
	  

	  
	  
	  
//监听表格复选框选择
  table.on('checkbox(demo)', function(obj){
    console.log(obj)
    var data=obj.data;
	 if(obj.type=="all"){
		
		 
		 var tables=table.cache.idTest;
		 if(obj.checked==true){
			 
		 }else{
			 
		 }
			 
	 }else{
		 if(obj.checked==true){
	       		$("#returnTotales").val($("#returnTotales").val()+data.sdId+","+data.muId+","+data.muName+","+data.mtName+","+data.muNumber+","+data.muPrice+","+data.subtotal+","+$("#returnNumber"+data.sdId).val()+","+$("#returnTotal"+data.sdId).val()+"#")
		 }else{
 
			 
			 
		 }
	 }
  });
  
 
  //表单重载
  var $ = layui.$, active = {
		  
		    reload: function(){
		      var demoReload = $('#demoReload');
		      
		      //执行重载
		      table.reload('idTest', {
		        page: {
		          curr: 1 //重新从第 1 页开始
		        }
		        ,where: {
		        	sellId: getParameter("id"),
		        	pdName: demoReload.val()
		        }
		      });
		    }/* ,getCheckData: function(){ //获取选中数据
			      var checkStatus = table.checkStatus('idTest')
			      ,data = checkStatus.data;
			      layer.alert(JSON.stringify(data));
			    }*/
		  };
  	  active['reload'] ? active['reload'].call(this) : '';
  
	  $('.demoTable .layui-btn').on('click', function(){
		
	    var type = $(this).data('type');
	    active[type] ? active[type].call(this) : '';
	  });
 

});		
$(function(){
	$("#yesReturn").click(function(){
		var url = "../../listenReturnGoods/salesReturn.action";
		var date = {"returns":$("#returnTotales").val(),"sellId":getParameter("id")}
		$.post(url,date,function(mes){
			if(mes.datas==0){
				parent.layer.msg(mes.msg,function(){
					parent.location.reload();
					icon:1;
				});
				$(".layui-laypage-btn")[0].click();
			}else{
				parent.layer.msg(mes.msg,function(){
					parent.location.reload();
					icon:2;
				});
			}
		},"json")
	})
})
function findKeyup(id){
	var price = $("#returnNumber"+id).parent().parent().prev().prev().children().html();
	var number = $("#returnNumber"+id).val();
	var sum = parseInt(price)*parseInt(number);
	$("#returnTotal"+id).val(sum);
}



